#
# Classifier for Postfix/Vmailer bounce messages
#
package Mail::Bounce::MixerPP;
use strict;

use vars qw(@ISA @patterns);

@ISA = qw(Mail::Bounce::Heuristic);

$patterns[0] = << 'EoF';
This report relates to your message:${-(?s:.*)}Subject: ${-.*}
  Message-ID: <${-\S+}>,
  To: ${ARRIVING_RECIPIENT-\S+}${-(?s:.*)}

Your message was not delivered to   ${FINAL_RECIPIENT-\S+}
        for the following reason:
        ${DIAGNOSTIC-(?s:.*)}

***** The following information is directed towards the local administrator
EoF
#
# Older PP variations did not use MIME for separating pieces
#
$patterns[1] = << 'EoF' . $patterns[0];

------------------------------ Start of body part 1

EoF

# From nms.rz.uni-kiel.de: Different wrapping
$patterns[2] = << 'EoF';
This report relates to your message:${-(?s:.*)}Subject: ${-.*}
  Message-ID: <${-\S+}>,
  To: ${ARRIVING_RECIPIENT-\S+}${-(?s:.*)}

Your message was not delivered to  
        ${FINAL_RECIPIENT-\S+} for the following reason:
        ${DIAGNOSTIC-(?s:.*)}

***** The following information is directed towards the local administrator
EoF

# SoftSwitch LMS 3.1.1 from DBMAIL.DEBIS.DE
$patterns[3] = << 'EoF';
This report relates to your message: ${-.*}
        of ${MSGDATE-.*}

Your message was not delivered to   ${FINAL_RECIPIENT-\S+}
        for the following reason:
        ${DIAGNOSTIC-(?s:.*)}

***** The following information is directed towards the local administrator
EoF


sub validate {
    my $self = shift;
    my $keywords;
    $keywords = $self->patternmatch($self->firstbodystring, @patterns);
    return defined($keywords);
}

    

sub recipients {
    my $self = shift;

    if (wantarray()) {
	my $res;
	my $keywords;
	$keywords = $self->patternmatch($self->firstbodystring, @patterns);
	if (defined($keywords)) {
	    $res = new Mail::Bounce::Address;
	    $res->type("permfail");
	    $res->action("failed");
	    my $diag = $$keywords{DIAGNOSTIC};
	    if ($diag =~ /^Unknown Address/) {
		$res->status("5.1.1 (Unknown user)");
	    } else {
		$res->status("5.0.0");
	    }
	    $diag =~ s/\n/ /g;
	    $res->diagnostic("Mixer; $diag");
	    $res->final_recipient($$keywords{FINAL_RECIPIENT});
	} else {
	    die "MixerPP: Unmatched pattern in recipients()\n";
	}
	return $res;
    } else {
	return 1;
    }
}
1;




